<template>
  <div>
    <el-card class="box-card">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="模板名称">
          <el-input
              v-model="formInline.templateName"
              placeholder="请输入内容"
              suffix-icon="el-icon-search"
              
            ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="changeSearch">搜索</el-button>
          <el-button @click='refreshInput'>重置</el-button>
        </el-form-item>
      </el-form>
       <el-button type="primary" @click='newOut'>新建</el-button>
       <el-button type="primary" @click='moreDelete'>批量删除</el-button>
    </el-card>
    <div class="list">
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column type="index" label="序号" width="60">
        </el-table-column>
        <el-table-column prop="templateName" label="模板名称"> </el-table-column>
        <el-table-column label="创建时间" prop="createTime" width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
         <i style="color: #339dff" @click="edit(scope.$index, scope.row)">编辑&nbsp;&nbsp;|&nbsp;&nbsp;</i>
         <i style="color: #339dff" @click="del(scope.row)">删除&nbsp;&nbsp;|&nbsp;&nbsp;</i>
         <i style="color: #339dff" @click="Out(scope.$index, scope.row)">打印</i>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pageNum"
        :page-sizes="[2, 3, 4, 5]"
        :page-size="query.pageSize"
        prev-text="上一页"
        next-text="下一页"
        layout=" prev, pager, next"
        :total="query.total"
      ></el-pagination>

      <div class="jumper">
        跳到第
        <input type="text" ref="pageNum" :value="query.pageNum" />
        页
      </div>
      <button @click="goPage">确定</button>
    </div>
  </div>
</template>

<script>
import {
gradetemplateList,
Delgradetemplate
} from "@/api/achievement/gradetemplate";
export default {
  data() {
    return {
      formInline: {
        templateName:'',
      },
      tableData: [],
      query: {
        pageNum: 1,
        pageSize: 6,
        total: 0,
      },
      ids:'',
    };
  },
  mounted() {
    this.getList()
  },
  methods: {
    async getList(){
       let res=await gradetemplateList(this.query)
       console.log(res)
       this.tableData=res.rows
       this.query.total = res.total;
    },
    // 分页
    // 改变每页条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val;
      this.getList();
    },
    //切换页数，执行方法
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val;
      this.getList();
    },
    goPage() {
      let { value } = this.$refs.pageNum;
      console.log("1", value);
      this.query.pageNum = Number(value);
      this.getList();
    },
    //批量
    handleSelectionChange(val) {
      console.log('23',val)
      var arrTostring = [];
      val.forEach(item => {
        if (arrTostring.indexOf(item.id) === -1) {
          arrTostring.push(item.templateId);
        }
      });
      this.ids = arrTostring.toString();
    },
    moreDelete() {
      console.log(this.ids);
      this.$confirm("确认删除记录吗?", "提示", {
        type: "warning"
      })
        .then(() => {
          Delgradetemplate({ ids: this.ids }).then(res => {
            console.log(res);
            this.$message.success("删除成功");
            this.getList();
          });
        })
        .catch(() => {});
    },
        // 重置
    refreshInput() {
      this.formInline.templateName=''
      this.getList();
    },
   //删除
   del(row) {
     console.log('233',row)
      this.$confirm("确认删除记录吗?", "提示", {
        type: "warning"
      })
        .then(() => {
          Delgradetemplate({ ids: row.templateId }).then(res => {
            console.log(res);
            this.$message.success("删除成功");
            this.getList();
          });
        })
        .catch(() => {});
    },
   // 搜索
    changeSearch() {
      gradetemplateList({ templateName: this.formInline.templateName}).then(
        res => {
          console.log('222',res);
          this.tableData = res.rows;
        }
      );
    },
    onSubmit() {
      console.log("submit!");
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },

    //跳转
  Out(index,row){
      console.log('23',row)
       this.$router.push({
        name: "OutGradetemplate",
        params:{
          list:row
        }
      });
    },
    edit(index,row){
      console.log('23',row)
       this.$router.push({
        name: "Editgradetemplate",
        params:{
          list:row
        }
      });
    },
    //新建跳转
    newOut(){
     this.$router.push({
        name: "Newgradetemplate",
      });
    }
  },
};
</script>

<style lang="scss" scoped>
.box-card {
  width: 98%;
  margin-left: 10px;
}
.list {
  width: 100%;
  background: #ffffff;
  .listone {
    width: 90%;
    margin-left: 30px;
    border: 1px solid #caedff;
    background: #e6f7ff;
  }
}
.demo-form-inline{
    margin-left: 33%;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: right;
  margin-top: 20px;
  margin-right: 150px;
  .jumper {
    font-size: 14px;
    margin-left: 20px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    input {
      width: 40px;
      height: 26px;
      margin: 0 5px;
      text-align: center;
      border: solid 1px #e6e6e6;
      border-radius: 5px;
      color: #666;
      outline-style: none;
    }
  }
  button {
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    background-color: #4895db;
    border: solid 1px #4895db;
    color: #fff;
    font-size: 14px;
    padding: 0 8px;
  }
}
</style>
